/*
 * MainDlg.h
 * 
 * Copyright (C) 2011 Gulian Lin.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#pragma once

#include <vector>
#include <string>

#include "USB_DevInfo.h"

class CMainDlg : public CDialogImpl<CMainDlg>
{
private:
	std::vector<USB_DevInfo> usb_dev_list_;
	HDEVNOTIFY dev_notify_handle_;
	NOTIFYICONDATA notify_icon_data_;
	CComboBoxEx port_combo_;
	CImageList icon_list_;
	CEdit mfg_edit_;
	CButton always_on_top_check_;
	CButton minize_check_;
	bool is_topmost_;
	bool is_minimize_active_;
	bool is_minimize_;

protected:
	int insertPortItem(const std::wstring &str, int num_item, int num_icon);
	bool setTooltipText(const std::wstring &tooltip_text);
	bool showBalloonTip(const std::wstring &tittle,
		const std::wstring &balloontip_text, 
		UINT timeouts, 
		DWORD info_flag);
	void getSysPort();

public:
	enum { IDD = IDD_MAINDLG };

	// Minimize message id
	enum { WM_SYSTEMTRAYICON = WM_USER + 1 };

	BEGIN_MSG_MAP(CMainDlg)
		MSG_WM_INITDIALOG(OnInitDialog)
		MSG_WM_DEVICECHANGE(OnDeviceChange)
		MSG_WM_SYSCOMMAND(OnSysCommand)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
		COMMAND_HANDLER(IDC_COMCOMBO, CBN_SELCHANGE, OnSelectChange)
		COMMAND_ID_HANDLER_EX(IDC_CHECK_ALWAYS_ON_TOP, OnAlwaysOnTop)
		COMMAND_ID_HANDLER_EX(IDC_CHECK_MINIMIZE, OnMinimize)
		COMMAND_ID_HANDLER_EX(SC_RESTORE, OnScRestore)
		COMMAND_ID_HANDLER_EX(SC_CLOSE, OnScClose)
		MESSAGE_HANDLER_EX(WM_SYSTEMTRAYICON, OnSystemTrayIcon)
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(CWindow wndFocus, LPARAM lInitPara);
	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnDeviceChange(UINT nEventType, DWORD dwData);
	LRESULT OnSelectChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnSysCommand(UINT nCommand, CPoint);
	LRESULT OnSystemTrayIcon(UINT, WPARAM wParam, LPARAM lParam);
	LRESULT OnScRestore(UINT, INT, HWND);
	LRESULT OnScClose(UINT, INT, HWND);
	void OnAlwaysOnTop(UINT uNotifyCode, int nID, HWND hWndCtl);
	void OnMinimize(UINT uNotifyCode, int nID, HWND hWndCtl);
};
